﻿/**
 * jQuery global.js
 */
$(function(){
	//　prevent default link #
	/*$('a[href=#]').click(function(e){
		e.preventDefault();
	});*/
	//set body height
	var $J_parnter_scroll = $('#J_parnter_scroll');	
	$(window).load(function(){
		var xHeight = $('#header').outerHeight() + $('#footer').outerHeight();
		var wHeight = $(window).height();
		var mHeight = $(".main").height();
		var cHeight = wHeight - xHeight; 
		if(cHeight > mHeight){
			if($J_parnter_scroll.length == 0){
				$(".main").css({
					"min-height" : cHeight
				});
			}
		}
	});
	
	// nav hover
	var $navigation = $('#navigation');
	$('li.navi', $navigation).mouseenter(function(){
		var self = $(this);
		self.find('.subnav').show();
	})
	.mouseleave(function(e){
		e.stopPropagation();
		var self = $(this);
		self.find('.subnav').hide();				 
	});
	
	// sign in
	
	var $J_sign_form = $('#J_sign_form');
    $('.username', $J_sign_form).setDefaultText('User name');
    $('.password', $J_sign_form)
        .setDefaultText('password')
        .keyup(function(e){
            if(e.which == 13){
                $('.btn_submit', $J_sign_form).click();
                return;
            }                                        
    });	
	
	
	/*
	$('.btn_submit', $J_sign_form).click(function(e){
		e.preventDefault();
		var self = $(this);
		var userval = $('.username', $J_sign_form).val(),
			userDefaultval = $('.username', $J_sign_form)[0].defaultValue,
			passval = $('.password', $J_sign_form).val(),
			passDefaultval = $('.password', $J_sign_form)[0].defaultValue;
		if(userval == '' || userval == userDefaultval){
			$("#loadp").hide();
			alert('Please check your user name, try again!');
		} else if(passval == '' ||  passval == passDefaultval){
			$("#loadp").hide();
			alert('Please check your user password, try again!');			
		} else {
			self.parents('form').submit();
		}
	});
	*/
	// join in
	var $J_join = $('#J_join');
	
	$('.btn_submit', $J_join).click(function(e){
		e.preventDefault();
		var self = $(this);		
		var select_memberType = $J_join.find('.select_memberType').val();
		if(select_memberType === ''){
			alert('Please select your Member Type, try again!')
		} else {
			self.parents('form').submit();
		}
	});

	/*scroll action*/
	function ScrollAction(listObj, listElem, speed, isSeries) {	//listObj为需要滚动的列表，  speed为滚动速度
		if(!listObj.length){return;}
			var id = '', //记录setInterval的标记id
				pos = listObj.position(),
				left = pos.left,		//列表的left
				aniLeft = left,				//记录当前运动时的left
				width = listObj.width();	//列表的高度
			var scrollUp = function() {
				aniLeft--;
				if(!isSeries) {	//isSeries变量控制是否连续滚动，false不连续，true连续
					if(aniLeft == -width) {	//不连续，滚动玩重新滚动
						listObj.css({'left': left});
						aniLeft = left;
					};
				} else {
					if(aniLeft == -listObj.children().eq(0).width()) {	//连续滚动
						var firstItem = listObj.children('li').eq(0).clone();
						listObj.append(firstItem);
						listObj.children('li').eq(0).remove();
						aniLeft = 26;
					};
					
				};
				listObj.css({'left': aniLeft + 'px'});
			};
			
			var hover = function(id) {
				listObj.hover(function() {
					clearInterval(id);
				}, function() {
					id = setInterval(scrollUp, speed);
				});
			};
			
			this.start = function() {
				id = setInterval(scrollUp, speed);
				hover(id);
			};
			
		};
	var $J_parnter_scroll_ul = $J_parnter_scroll.find('ul');
	if($J_parnter_scroll_ul.length>0){
		var SA = new ScrollAction($J_parnter_scroll_ul, 'li', 50, true);
		SA.start();
	}
	
});
